package com.javasoft.controller.XGX;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javasoft.entity.XGX.Practice;
import com.javasoft.entity.XGX.Question;
import com.javasoft.entity.XGX.WrongQuestion;
import com.javasoft.service.XGX.impl.WrongTableImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/PracticeFromWrong")
public class WrongController {

    @Autowired
    private WrongTableImpl wrongTable_impl;


    /**
     * 查询错题库
     * @param questionId
     * @param des
     * @param currentPage
     * @param pageSize
     * @param knoPoint
     * @param type
     * @param subject
     * @param difRank
     * @return
     */

    @GetMapping("/search")
    public Page<WrongQuestion> searchPage(@RequestParam(value = "id",required = false) Long questionId,//id不是必须的,可以设置成required = false
                                    @RequestParam(value = "des",required = false) String des,
                                    @RequestParam(defaultValue = "1",value = "currentPage") Integer currentPage,
                                    @RequestParam(defaultValue = "15",value = "pageSize") Integer pageSize,
                                    @RequestParam(value = "knoPoint",required = false) String knoPoint,
                                    @RequestParam(value = "type",required = false) String type,
                                    @RequestParam(value = "subject",required = false) String subject,
                                    @RequestParam(defaultValue = "-1",value = "difRank",required = false) Integer difRank){
        return wrongTable_impl.searchWrongTable(questionId, subject, knoPoint, des, type, difRank, currentPage, pageSize);
    }


    /**
     * 根据错题库生成训练题
     * @param currentPage
     * @param pageSize
     * @param subject
     * @return
     */

    @GetMapping("/practice")
    public Page<Practice> practicePage(
                               @RequestParam(defaultValue = "1",value = "currentPage") Integer currentPage,
                               @RequestParam(defaultValue = "15",value = "pageSize") Integer pageSize,
                               @RequestParam(value = "subject") String subject
                             ){
        return wrongTable_impl.getPracticeByWrongTable(subject,
                currentPage,
                pageSize);
    }


    /**
     * 更新或保存新的题目
     * @param newQuestion
     * @return id
     */
    @PostMapping("/save")
    public String save(@RequestBody WrongQuestion newQuestion){
        return wrongTable_impl.saveOrUpdateByBody(newQuestion);//这个是impl里面定义的
    }

    /**
     * 获取全部错题
     * @param currentPage
     * @param pageSize
     * @return
     */

    @GetMapping("/all")
    public Page<WrongQuestion> getAllData(@RequestParam(defaultValue = "1",value = "currentPage") Integer currentPage,
                                     @RequestParam(defaultValue = "15",value = "pageSize") Integer pageSize) {
        return wrongTable_impl.getAllData(currentPage, pageSize);
    }


    @PostMapping("/delete")
    public String delete(@RequestBody List<Integer> ids){
        return wrongTable_impl.deleteBatchIds(ids);
    }





}




